<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="decorator" content="default" />
<title>报告附页管理</title>
<script type="text/javascript">
	$(document).ready(
			function() {
				var fyId = '${fy.id}';
				var notnew = '${fy.notnew}';
				if(fyId || notnew) {
					$('#projectId').select2('readonly',true);
					$('#subPro').select2('readonly',true);
					$('#jjmc').attr('readonly',true);
					$('#jjbh').select2('readonly',true);
				}
				$("#qxxz").select2({tags:eval('${fns:getDictValueListJson('qxxz')}'),maximumSelectionSize: 1});
				$("#qxdl").select2({tags:eval('${fns:getDictValueListJson('qxdl')}'),maximumSelectionSize: 1});

				$('#projectId').val('${fy.project.id}').trigger('change');
				$("#value").focus();
				$("#inputForm")
						.validate(
								{
									submitHandler : function(form) {
										loading('正在提交，请稍等...');
										form.submit();
									},
									errorContainer : "#messageBox",
									errorPlacement : function(error, element) {
										$("#messageBox").text("输入有误，请先更正。");
										if (element.is(":checkbox")
												|| element.is(":radio")
												|| element.parent().is(
														".input-append")) {
											error.appendTo(element.parent()
													.parent());
										} else {
											error.insertAfter(element);
										}
									}
								});
			});

	function loadSubProject(projectId) {
		if (!projectId) {
			$('#subPro').html('<option value="">请选择单位工程</option>');
			$('#subPro').select2('val', '');
			return;
		}
		$.post('${ctx}/project/subProject/listSubByPro', {
			projectId : projectId
		}, function(data, textStatus, jqXHR) {
			var html = '<option value="">请选择单位工程</option>';
			for (var i = 0; i < data.length; i++) {
				html += '<option value="'+data[i].id+'">' + data[i].name
						+ '</option>';
			}
			$('#subPro').html(html);
			$('#subPro').val('${fy.subProject.id}').trigger('change');
		}, 'json');

	}
	var jj = {};
	function loadGXHBySub(subProjectId) {
		console.log(subProjectId);
		if (!subProjectId) {
			$('#jjbh').html('<option value="">请选择管线号</option>');
			$('#jjbh').select2('val', '');
			return;
		}
		$.post('${ctx}/project/tz/listGXHBySub', {
			subProjectId : subProjectId
		}, function(data, textStatus, jqXHR) {
			var html = '<option value="">请选择管线号</option>';
			for (var i = 0; i < data.length; i++) {
				jj[data[i].gxh] = data[i].jjmc;
				html += '<option value="'+data[i].gxh+'">' + data[i].gxh
						+ '</option>';
			}
			$('#jjbh').html(html);
			$('#jjbh').val('${fy.jjbh}').trigger('change');
		}, 'json');
	}

	function mcbhChange(obj) {
		$('#jjmc').val(jj[obj.value]);
	}
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/project/fy/list?jjbh=${fy.jjbh}&gg=${fy.gg}&hkbh=${fy.hkbh}">报告附页列表</a></li>
		<li class="active"><a href="${ctx}/project/fy/form">报告附页添加</a></li>
	</ul>
	<common:message content="${message}" />
	<form:form id="inputForm" modelAttribute="fy"
		action="${ctx}/project/fy/save" method="post" class="form-horizontal">
		<form:hidden path="id" />
		<div class="row">
			<div class="span6">
				<div class="control-group">
					<label class="control-label">工程:</label>
					<div class="controls">
						<select name="project.id" class="input-large required"
							onchange="loadSubProject(this.value)" id="projectId" >
							<option value="">请选择工程</option>
							<c:forEach items="${projectList}" var="p">
								<option value="${p.id}">${p.name}</option>
							</c:forEach>
						</select> <span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
			</div>
			<div class="span6">
				<div class="control-group">
					<label class="control-label">单位工程:</label>
					<div class="controls">
						<select id="subPro" name="subProject.id"
							class="input-large required" onchange="loadGXHBySub(this.value)">
							<option value="">请选择单位工程</option>
						</select> <span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="span6">
				<div class="control-group">
					<label class="control-label">检件名称:</label>
					<div class="controls">
						<form:input path="jjmc" htmlEscape="false" maxlength="50"
							class="required" readonly="true" />
						<span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
			</div>
			<div class="span6">
				<div class="control-group">
					<label class="control-label">管线编号:</label>
					<div class="controls">
						<select id="jjbh" name="jjbh" class="input-large required"
							onchange="mcbhChange(this)">
							<option value="">请选择管线编号</option>
						</select> <span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
			</div>
		</div>
		<c:if test="${not empty fy.id or fy.notnew=='yes'}">
			<div class="row">
				<div class="span6">
					<div class="control-group">
						<label class="control-label">焊口编号:</label>
						<div class="controls">
							<form:input path="hkbh" htmlEscape="false" maxlength="50"
								class="required" />
							<span class="help-inline"><font color="red">*</font> </span>
						</div>
					</div>
				</div>
				<div class="span6">
					<div class="control-group">
						<label class="control-label">片号:</label>
						<div class="controls">
							<form:input path="ph" htmlEscape="false" maxlength="50"
								class="required" />
							<span class="help-inline"><font color="red">*</font> </span>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="span6">
					<div class="control-group">
						<label class="control-label">规格:</label>
						<div class="controls">
							<form:input path="gg" htmlEscape="false" maxlength="50"
								class="required" />
							<span class="help-inline"><font color="red">*</font> </span>
						</div>
					</div>
				</div>
				<div class="span6">
					<div class="control-group">
						<label class="control-label">焊工号:</label>
						<div class="controls">
							<form:input path="hgh" htmlEscape="false" maxlength="50"
								class="required" />
							<span class="help-inline"><font color="red">*</font> </span>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="span6">
					<div class="control-group">
						<label class="control-label">缺陷性质:</label>
						<div class="controls">
							<form:hidden path="qxxz" htmlEscape="false" maxlength="50"
								class="required input-large" />
							<span class="help-inline"><font color="red">"圆形缺陷－A", "条形缺陷－B", "未熔合－C", "未焊透－D",
									"裂纹―E", "咬边―F", "内凹－W" </font> </span>
						</div>
					</div>
				</div>
				<div class="span6">
					<div class="control-group">
						<label class="control-label">缺陷定量:</label>
						<div class="controls">
							<form:hidden path="qxdl" htmlEscape="false" maxlength="50"
										 class="input-large" />
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="span6">
					<div class="control-group">
						<label class="control-label">评定结果:</label>
						<div class="controls">
							<form:select path="pdjg" class="input-large required">
								<form:option value="" label="请选择" />
								<form:options items="${fns:getDictList('dict_fy_pdjg')}"
									itemLabel="label" itemValue="value" htmlEscape="false" />
							</form:select>
							<span class="help-inline"><font color="red">*</font> </span>
						</div>
					</div>
				</div>
				<div class="span6">
					<div class="control-group">
						<label class="control-label">备注:</label>
						<div class="controls">
							<form:input path="remarks" htmlEscape="false" maxlength="50" />
						</div>
					</div>
				</div>
			</div>
		</c:if>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="submit"
				value="保 存" />&nbsp; <input id="btnCancel" class="btn"
				type="button" value="返 回" onclick="history.go(-1)" />
		</div>
	</form:form>
</body>
</html>